package net.cl.tools.json;

public class JsonElement implements Json {

	private static final long serialVersionUID = 4576337269429190124L;
	private String value;
	private boolean needQuote = true;

	protected JsonElement(String value) {
		this.value = value;
	}

	protected JsonElement(String value, boolean needQuote) {
		this.value = value;
		this.needQuote = needQuote;
	}

	protected JsonElement(Number value) {
		this.value = String.valueOf(value);
	}

	protected JsonElement(boolean value) {
		this.value = String.valueOf(value);
	}

	protected String getValue() {
		return JsonBuilder.convert(value);
	}

	protected long toLong() {
		return Long.valueOf(value);
	}

	protected double toDouble() {
		return Double.valueOf(value);
	}

	protected boolean toBoolean() {
		return Boolean.valueOf(value);
	}

	public String toString() {
		return (needQuote ? "\"" : "") + JsonBuilder.unEscape(value) + (needQuote ? "\"" : "");
	}

}
